﻿using HCore;

namespace MEat
{
    public class GoalThink : GoalComposite<Dummy>
    {
        public GoalThink(Dummy owner) : base(owner, GoalType.Think)
        {
        }

        public override void Activate()
        {
            _status = GoalStatus.Active;
        }

        public override GoalStatus Process()
        {
            ActivateIfInactive();

            GoalStatus subgoalStatus = ProcessSubgoals();

            if (subgoalStatus == GoalStatus.Completed || subgoalStatus == GoalStatus.Failed)
            {
                _status = GoalStatus.Inactive;
            }

            return _status;
        }

        public override void Terminate()
        {
        }

        public bool NotPresent(int goalType)
        {
            if (_subGoalList.Count > 0)
            {
                return _subGoalList.First.Value.goalType != goalType;
            }

            return true;
        }

        public void AddGoalSeekToPosition(Vector3 position)
        {
            RemoveAllSubgoals();
            AddSubgoal(new GoalArriveToPosition(_owner, position));
        }
    }
}